home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-11-29 | 1.6 KB | 83 lines | [TEXT/MPS ] |
- // ©1992 Conrad Carlen & Manuel Veloso. All rights reserved.
- #ifndef _PREPROCESS_
- #include "Preprocess.h"
- #endif
-
- #ifndef __STRING__
- #include <string.h>
- #endif
-
- #ifdef _cplusplus
- extern "C"
- {
- #endif
- short stripLF(char *buffer, const short count);
- short stripEcho(char *buffer, short count, char *compare);
- short addReturn(char *buffer, short count);
- short stripExecutivePrompt(char *buffer, short count);
- #ifdef _cplusplus
- }
- #endif
-
- short preprocessRead(char *buffer, short count, char */* compare */)
- {
- count = stripLF(buffer, count);
- // count = stripEcho(buffer, count, compare); // should be after lf conversion, since it checks returns
- return count;
- }
-
- short stripLF(char *buffer, const short count)
- {
- char *scan = buffer;
- char *stop = scan + count;
-
- do
- {
- if (*scan == 0x0a)
- {
- *scan = 0x0d;
- }
- scan++;
- } while (scan < stop);
- return count;
- }
-
- short stripEcho(char *buffer, short count, char *compare)
- {
- if (!memcmp(buffer, compare, count))
- {
- count = 0; // it’s an echo! Kill it off.
- }
- return count;
- }
-
- short preprocessWrite(char *buffer, short count)
- {
- count = stripExecutivePrompt(buffer, count);
- count = addReturn(buffer, count); // replaces trailing null w/return, so no clib stuff after this
- return count;
- }
-
- short addReturn(char *buffer, short count)
- {
- buffer[count-1] = 0x0d;
- return count;
- }
-
- short stripExecutivePrompt(char *buffer, short count)
- {
- char *theString = buffer, *theSubstring;
- short length;
-
- if ((theString[0] == 'P') && (theString[1] == 'S'))
- {
- length = 2;
- while (theString[length] == '>')
- {
- length++;
- }
- memcpy(theString, theString+length, strlen(theString));
- count -= length;
- }
- return count;
- }